import { request } from "./request";

// 测试
// export const test = () => request({url: '/test', method: 'get'})

// 获取验证码
// export const reqGetCode = () => request({url: '/user/verifyCode', method: 'get'})

// 登录
export const reqLogin = (code, phone) => request({url:`/user/login?code=${code}&phone=${phone}`, method: 'get'})

// 获取用户信息
export const reqGetUserInfo = () => request({url: '/user', method: 'get'})

// 获取地址
export const reqGetAddress = () => request({url: '/address', method: 'get'})

// 删除地址信息
// /address/{addressId}
export const reqDeleteAddress = (addressId) => request({url: `/address/${addressId}`, method: 'delete'})

// 新增地址信息
export const reqAddAddress = (address) => request({url: '/address', method: 'post', data: address})
// export const reqAddOrUpdateAddress = (address) => {
// 	if(address.id) {
// 		request({url: '/address', method: 'put', data: address})
// 	}else {
// 		request({url: '/address', method: 'post', data: address})
// 	}
// }

// 跳转地址信息修改
// /address/{addressId}
export const reqToUpdateAddress = (addressId) => request({url: `/address/${addressId}`, method: 'get'})

// 修改地址
export const reqUpdateAddress = (address) => request({url: '/address', method: 'put', data: address})

// 修改昵称
// /user/nickName/{nickName}
export const reqUpdateName = (nickName) => request({url: `/user/nickName/${nickName}`, method: 'put'})

// 修改头像
// /user/avatar/{imgUrl}
export const reqUpdateImg = (imgUrl) => request({url: `/user/avatar/${imgUrl}`, method: 'put'})

// 综合排序
export const reqSynthesis = () => request({url: '/dishes/all', method: 'get'})

// 距离排序
// /dishes/distance
export const reqDistance = () => request({url: '/dishes/distance', method:'get'})

// 销量排序
// /dishes/onSale
export const reqSale = () => request({url: '/dishes/onSale', method: 'get'})

// 星级排序
// /dishes/score
export const reqScore = () => request({url: '/dishes/score', method: 'get'})

// 分类
// /category
export const reqCategory = () => request({url: '/category', method: 'get'})

// 店铺信息
// /shop/{id}
export const reqSortShop = (id) => request({url: `/shop/${id}`, method: 'get'})

// 分类商家信息
export const reqCateShop = (id) => request({url: `/shop/shop_category/${id}`, method: 'get'})

// 商家菜品信息
// /dishes		category_id		 shop_id
export const reqShopDishes = (category_id, shop_id) => request({url: '/dishes', data: {category_id, shop_id}, method: 'get'})

// 添加购物车
// /cart/insert
export const reqAddCart = (cart, shopId, userId) => request({url: `/cart/insert`, data: {cart, shopId, userId}, method: 'post'})


// 获取购物车信息
// /cart   shopId  userId
export const reqCartInfo = (shopId, userId) => request({url: '/cart', data: {shopId, userId}, method: 'get'})

// 删除购物车信息
// /cart
export const reqDeleteCart = (dishesId, shopId, userId) => request({url: '/cart', data: {dishesId, shopId, userId0}, method: 'delete'})